package com.bcbim.api_web.space.controller;

import com.alibaba.fastjson.JSONObject;
import com.bcbim.common.response.annotation.Translate;
import com.bcbim.common.response.vo.ReturnMsg;
import com.bcbim.operation_maintenance_interface.department.dto.DepartmentDTO;
import com.bcbim.operation_maintenance_interface.space.dto.SpaceRisingSunStatisticsDTO;
import com.bcbim.operation_maintenance_interface.space.dto.SpaceStatisticsDTO;
import com.bcbim.operation_maintenance_interface.space.service.SpaceStatisticsService;
import com.bcbim.operation_maintenance_interface.space.vo.SpaceRisingSunStatisticsVO;
import com.bcbim.operation_maintenance_interface.space_type.dto.SpaceTypeDTO;
import org.apache.commons.lang3.StringUtils;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @version V 1.0.0
 * @Description：空间统计controller
 * @Author: haomeijie
 * @Date: 2022/4/20 18:11
 **/
@RestController
@RequestMapping("/spaceStatistics")
public class SpaceStatisticsController {


    @Reference(protocol = "dubbo", group = "spaceStatistics", version = "1.0.0")
    private SpaceStatisticsService spaceStatisticsServiceImpl;


    /**
     * 空间统计堆积图
     *
     * @param statisticsDTO
     * @return Map<String, Object>
     * @Author: haomeijie
     * @Date: 2022/4/20 10:45
     */
    @RequestMapping("/getStackingDiagram")
    public ReturnMsg getStackingDiagram(SpaceStatisticsDTO statisticsDTO) {
        //整理筛选条件
        if (StringUtils.isNotEmpty(statisticsDTO.getSpaceType())) {
            List<SpaceTypeDTO> typeDTOList = JSONObject.parseArray(statisticsDTO.getSpaceType(), SpaceTypeDTO.class);
            statisticsDTO.setSpaceTypeIds(typeDTOList);
        }
        if (StringUtils.isNotEmpty(statisticsDTO.getDepartment())) {
            List<DepartmentDTO> departmentDTOList = JSONObject.parseArray(statisticsDTO.getDepartment(), DepartmentDTO.class);
            statisticsDTO.setDepartmentIds(departmentDTOList);
        }
        Map<String, Object> stackingDiagram = spaceStatisticsServiceImpl.getStackingDiagram(statisticsDTO);
        return ReturnMsg.consSuccess(stackingDiagram);
    }
    /**
     * @Description:  空间统计旭日图
     * @Date:  2022/4/24 12:37
     * @Param: [statisticsDTO]
     * @return: com.bcbim.common.response.vo.ReturnMsg
     * @Author: lihonggang
     **/
    @Translate
    @RequestMapping("/getSunburstIllustration")
    public ReturnMsg getSunburstIllustration(SpaceRisingSunStatisticsDTO spaceRisingSunStatisticsDTO) {
        //整理筛选条件
        if (StringUtils.isNotEmpty(spaceRisingSunStatisticsDTO.getSpaceType())) {
            List<SpaceTypeDTO> typeDTOList = JSONObject.parseArray(spaceRisingSunStatisticsDTO.getSpaceType(), SpaceTypeDTO.class);
            spaceRisingSunStatisticsDTO.setSpaceTypeIds(typeDTOList);
        }
        if (StringUtils.isNotEmpty(spaceRisingSunStatisticsDTO.getDepartment())) {
            List<DepartmentDTO> departmentDTOList = JSONObject.parseArray(spaceRisingSunStatisticsDTO.getDepartment(), DepartmentDTO.class);
            spaceRisingSunStatisticsDTO.setDepartmentIds(departmentDTOList);
        }
        List<SpaceRisingSunStatisticsVO> list = spaceStatisticsServiceImpl.getSunburstIllustration(spaceRisingSunStatisticsDTO);
        return ReturnMsg.consSuccess(list);
    }
}
